using System;

namespace SolarDevices
{
    public class RegisterTableBase
    {

        public delegate string DoConvert(int address);

        protected ushort[] _data;
        protected ushort[] Data
        {
            get { return _data; }
        }

        protected static int _offset;
        protected static int Offset
        {
            get { return _offset; }
        }

        protected string LSB(int address)
        {
            var n = LSBVal(address);
            return n.ToString();
        }

        protected int LSBVal(int address)
        {
            var p = Data[address - Offset];
            var n = p & 0x00ff;
            return n;
        }

        protected string MSB(int address)
        {
            var n = MSBVal(address);
            return n.ToString();
        }

        protected int MSBVal(int address)
        {
            var p = Data[address - Offset];
            var n = p >> 8;
            return n;
        }

        protected string U16(int address)
        {
            var p = Data[address - Offset];
            return p.ToString();
        }

        protected string U16_OneDec(int address)
        {
            var p = Data[address - Offset];
            Double d = p;
            d = d / 10;
            return d.ToString("f1");
        }

        protected string U32_OneDec(int address)
        {
            UInt32 l = Data[address - Offset + 1];
            l = l << 16;
            var r = l | Data[address - Offset];
            Double d = r;
            d = d / 10;
            
            return d.ToString("f1");
        }

        protected string U32(int address)
        {
            var r = U32Val(address);
            return r.ToString();
        }

        protected string U32X(int address)
        {
            var r = U32Val(address);
            return r.ToString("X");
        }

        protected uint U32Val(int address)
        {
            UInt32 l = Data[address - Offset + 1];
            l = l << 16;
            var r = l | Data[address - Offset];
            return r;
        }


    }
}